{extend name="common/base"}
{block name="title"}首页{/block}
{block name="content"}
        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">新增商品固定属性</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr"> 
                                <form class="am-form tpl-form-border-form tpl-form-border-br" action="{:Url('/admin/goods/insertAttributes')}" enctype="multipart/form-data" method="post">
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品名称 </label>
                                        <div class="am-u-sm-9">
                                            <select name="goods_id" id="sel1" style="width:30%;">
                                                <option value="null" style="color:#888;" selected>无</option>
                                                {volist name="goods_list" id="va"}
                                                <option value="{$va.id}" style="color:#888;">{$va.name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                    <div id="afterDiv"></div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>                
            </div>
        </div>

<script>
$("select#sel1").change(function(){
    getGoodList($(this).val());
});
//获取商品数据
function getGoodList(id){
    $.ajax({
        url:"{:Url('admin/Goods/getGoodList')}",
        type:"get",
        data:{id:id},
        dataType:"json",//数据通信的类型            
        success:function(data){
            if($("#sel1").val()=='null'){
                $("#afterDiv").empty();
            }else{
                $("#afterDiv").empty();
                console.log(data);
                var length = data.length;
                // alert(length);
                for(var i=0;i<length;i++){
                    if(data[i].son){
                        for(var k=0;k<data[i].son.length;k++){
                            $("#afterDiv").append('<input type="hidden" value="'+data[i].son[k].id+'" name="guigeType_id[]"><div class="am-form-group"><label for="user-name" class="am-u-sm-3 am-form-label">商品规格 </label><div class="am-u-sm-9"><input type="text" value="'+data[i].name+'+'+data[i].son[k].name+'" class="tpl-form-input" id="user-name" style="width:20%;float:left;margin-right:8px;" disabled><label for="user-name" class="am-u-sm-1 am-form-label">价钱: </label><input type="text" value="" name="price[]" class="tpl-form-input" placeholder="请输入价钱" id="user-name" style="width:13%;float:left;"><label for="user-name" class="am-u-sm-1 am-form-label">积分: </label><input type="text" value="" name="jifen[]" class="tpl-form-input" placeholder="请输入积分" id="user-name" style="width:13%;float:left;"><label for="user-name" class="am-u-sm-1 am-form-label">库存: </label><input type="text" value="" name="kucun[]" class="tpl-form-input" placeholder="请输入库存" id="user-name" style="width:13%;float:left;"></div></div>');
                        }
                    }else{
                        $("#afterDiv").append('<input type="hidden" value="'+data[i].id+'" name="guigeType_id[]"><div class="am-form-group"><label for="user-name" class="am-u-sm-3 am-form-label">商品规格 </label><div class="am-u-sm-9"><input type="text" value="'+data[i].name+'" class="tpl-form-input" id="user-name" style="width:20%;float:left;margin-right:8px;" disabled><label for="user-name" class="am-u-sm-1 am-form-label">价钱: </label><input type="text" value="" name="price[]" class="tpl-form-input" placeholder="请输入价钱" id="user-name" style="width:13%;float:left;"><label for="user-name" class="am-u-sm-1 am-form-label">积分: </label><input type="text" value="" name="jifen[]" class="tpl-form-input" placeholder="请输入积分" id="user-name" style="width:13%;float:left;"><label for="user-name" class="am-u-sm-1 am-form-label">库存: </label><input type="text" value="" name="kucun[]" class="tpl-form-input" placeholder="请输入库存" id="user-name" style="width:13%;float:left;"></div></div>');
                    }
                }
                if(length!=0){
                    $("#afterDiv").append('<div class="am-form-group" id="subDiv"><div class="am-u-sm-9 am-u-sm-push-3"><button type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success ">确认提交</button></div></div>');
                }                
            }  
        }
    });
}
</script>
{/block}